//
//  YPCellFactory.m
//  project
//
//  Created by 姚敦鹏 on 2018/10/12.
//  Copyright © 2018年 rocHome. All rights reserved.
//

#import "YPCellFactory.h"
#import "YPBaseTableViewCell.h"
#import "YPBaseCollectionViewCell.h"

@implementation YPCellFactory

+ (__kindof YPBaseTableViewCell *)createCellWithModel:(YPBaseModel *)model
                                   tableView:(UITableView *)tableView
                                   indexPath:(NSIndexPath *)indexPath
{
    // model 的类名
    NSString *modelName = [NSString stringWithUTF8String:object_getClassName(model)];
    
    // 对应 在 TableView 中注册 ReuseIdentifier
    NSString *cellReuseIdentifier = [[modelName substringToIndex:modelName.length - 5] stringByAppendingString:@"TableViewCell"];
    
    YPBaseTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellReuseIdentifier forIndexPath:indexPath];
    
    cell.dataModel = model;
    
    return cell;
}

/**
 cell 工厂
 
 @param model 模型
 @param collectionView collectionView
 @param indexPath indexPath
 @return cell
 */
+ (__kindof YPBaseCollectionViewCell *)createCellWithModel:(YPBaseModel *)model
                              collectionView:(UICollectionView *)collectionView
                                   indexPath:(NSIndexPath *)indexPath
{
    // model 的类名
    NSString *modelName = [NSString stringWithUTF8String:object_getClassName(model)];
    
    // 对应 在 CollectionView 中注册 ReuseIdentifier
    NSString *cellReuseIdentifier = [[modelName substringToIndex:modelName.length - 5] stringByAppendingString:@"CollectionViewCell"];
    
    YPBaseCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellReuseIdentifier forIndexPath:indexPath];
    
    cell.dataModel = model;
    
    return cell;
}

@end
